import { FObject } from "../../Support/FObject";
import { PlayerVO } from "../Player/PlayerVO";
import { GameDataManager } from "../../Managers/GameDataManager";

export default class RoomVO extends FObject {
    public static ClassName: string = "RoomVO";

    
    CreatedAt: number = null //创建时间
    Creator: number = null //创建人
    Title: number = null; //房间配置标题
    Desc: string = null  //游戏描述
    Mode: number = null
    Round: number = null //已经进行的游戏局数
    Status: number = null   //桌子的游戏状态
    ServerPos : number = null

    private _players : {[key:string]:PlayerVO} = {}


    public addPlayer (player:PlayerVO)  : void {
        this._players = {}

        for(let idx in player){
            let p = new PlayerVO()
            p.inject(player[idx])
            if(p.acId == GameDataManager.game.playerId){
                this.ServerPos = p.deskPos
            }
            this._players[player[idx].acId] = p
            // console.log(this._players)
        }
    }

    public getPlayerAll() : {[key:string]:PlayerVO}{
        return this._players
    }

    public getPlayerByid(uid:number) : PlayerVO{
        return this._players[uid]
    }

    public getSelfPlayer():PlayerVO{
        return this._players[GameDataManager.game.playerId]
    }

    public getMySeat() : number {
        return this.ServerPos
    }

    public getLocalPost(seat : number) : number{
        return (4 - this.getMySeat() + seat) % 4;
    }


}